package org.irri.smta.repository;

import java.util.List;

import javax.inject.Named;

import org.irri.smta.domain.ReportLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

@Named("reportLogRepository")
public interface IReportLogRepository extends JpaRepository<ReportLog, Long>,
		JpaSpecificationExecutor<ReportLog> {

	@Transactional(readOnly = true)
	@Query("SELECT o FROM ReportLog o ORDER BY o.createdDate DESC")
	List<ReportLog> findAllOrdered();

	@Transactional(readOnly = false, rollbackFor = Exception.class)
	@Modifying
	@Query(value = "TRUNCATE TABLE report_log", nativeQuery = true)
	void deleteReportLog();

}
